//
//  TableViewDataSource.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 15/9/23.
//  Copyright © 2015年 GripMeMory. All rights reserved.
//

#import "TableViewDataSource.h"

@interface TableViewDataSource ()

@property (nonatomic, strong) NSArray *items;
@property (nonatomic, copy) NSString *cellIdentifier;
@property (nonatomic, copy) TableViewCellConfigurBlock configurecellBlock;

@end

@implementation TableViewDataSource

- (id)init{
    return nil;
}

- (id)initWithItems:(NSArray *)anItems cellIdentifier:(NSString *)anCellIdentifier configureBlock:(TableViewCellConfigurBlock)aCellConfigureBlock{
    self = [super init];
    if (self) {
        self.items = anItems;
        self.cellIdentifier = anCellIdentifier;
        self.configurecellBlock = [aCellConfigureBlock copy];
    }
    return self;
}

- (id)itemAtIndexPath:(NSIndexPath *)indexpath{
    return self.items[indexpath.row];
}

#pragma mark - TableView DataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath];
    id item = [self itemAtIndexPath:indexPath];
    self.configurecellBlock(cell, item);
    return cell;
}

@end
